const storageUtil = {
  /**
   * 存储localStorage
   */
  setStore(key, data) {
    if (!key) return
    if (typeof data !== 'string') {
      data = JSON.stringify(data)
    }
    window.localStorage.setItem(key, data)
  },

  /**
   * 获取 字符串
   */
  getString(key, defValue) {
    if (!key) return defValue
    let res = window.localStorage.getItem(key)
    if (!res) return defValue
    return res
  },
  /**
   * 获取 [json, bool等]
   */
  getObject(key, defValue) {
    if (!key) return defValue
    let res = window.localStorage.getItem(key)
    if (!res) return defValue
    return JSON.parse(res)
  },

  /**
   * 删除localStorage
   */
  removeStore(key) {
    if (!key) return
    window.localStorage.removeItem(key)
  },
}

export default storageUtil